package com.itmuch.cloud.study.controller;

import com.itmuch.cloud.study.dao.UserDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.itmuch.cloud.study.entity.User;
import com.itmuch.cloud.study.repository.UserRepository;

/**
 * @author lrf
 */
@RestController
public class UserController {

    private static Logger logger = LoggerFactory.getLogger(UserController.class);

    private final UserRepository userRepository;
    private final UserDao userDao;

    @Autowired
    public UserController(UserRepository userRepository, UserDao userDao) {
        this.userRepository = userRepository;
        this.userDao = userDao;
    }


    /**
     * GetMapping是Spring4.3的新注解
     * @param id userId
     * @return User
     */
    @GetMapping("/{id}")
    public User findById(@PathVariable Long id) {
        User findOne = this.userRepository.findOne(id);
        logger.info("findOne = " + findOne);
        return findOne;
    }

    @GetMapping("/dao/{id}")
    public User findOne(@PathVariable Long id) {
        User one = this.userDao.findOne(id);
        logger.info("user = {}", one);
        return one;
    }
}
